# # backup_frame.py
# from PyQt5.QtWidgets import QFrame, QLabel, QLineEdit, QTextEdit
# from PyQt5.QtWidgets import QPushButton, QFileDialog, QApplication
# from PyQt5.QtGui import QFont
# from PyQt5.QtGui import QPixmap, QIcon
# from PyQt5.QtCore import QSize, Qt  # 导入 QSize
#
#
# class BackupFrame(QFrame):
#     def __init__(self, parent=None, run_detection=None):
#         super().__init__(parent)
#         self.setStyleSheet("background-color: white; border: 2px solid white;")
#         self.setFixedSize(440, 140)
#         self.setGeometry(20, 440 + 20 + 320, 440, 140)
#         # 你可以在这里添加该框架的其他功能代码
#
#         self.set_title()  # 添加标题
#         self.run_detection = run_detection  # 保存传入的检测函数
#
#         # 创建按钮
#         self.button1 = QPushButton("运行代码", self)
#         self.button2 = QPushButton("退出系统", self)
#         self.button3 = QPushButton("停止检测", self)  # 新增停止检测按钮
#
#         # 设置按钮的位置和大小
#         self.button1.setGeometry(15, 80, 125, 50)
#         self.button2.setGeometry(300, 80, 125, 50)
#         self.button3.setGeometry(17.5+140, 80, 125, 50)  # 停止按钮位置
#
#         # 调整按钮文字大小
#         font = QFont()
#         font.setPointSize(14)  # 设置文字大小为14
#         self.button1.setFont(font)
#         self.button2.setFont(font)
#         self.button3.setFont(font)
#
#         # 设置按钮图标
#         # self.set_button_icon(self.button1, "ui/image/icons_run.png")  # 替换为实际路径
#         # self.set_button_icon(self.button2, "ui/image/icons_Esc.png")  # 替换为实际路径
#         # self.set_button_icon(self.button3, "ui/image/icons_Esc.png")  # 替换为停止图标
#
#         # 设置按钮的样式（包括凸起和下陷效果）
#         self.set_button_style(self.button1,  background_color="#90EE90")
#         self.set_button_style(self.button2,  background_color="#FFB6C1")
#         self.set_button_style(self.button3,  background_color="#FFFFE0")
#
#         # 连接按钮的点击事件
#         self.button1.clicked.connect(self.run_code)
#         self.button2.clicked.connect(self.exit_system)
#         self.button3.clicked.connect(self.stop_detection)  # 停止按钮的点击事件
#
#     def set_button_icon(self, button, image_path):
#         # 设置按钮的图标
#         icon = QIcon(image_path)
#         button.setIcon(icon)
#         button.setIconSize(QSize(40, 40))  # 设置图标的大小
#
#     def set_button_style(self, button, background_color="#f0f0f0", border_color="#ccc", pressed_color="#ddd"):
#         # 设置按钮的样式
#         button.setStyleSheet(f"""
#             QPushButton {{
#                 background-color: {background_color};
#                 border: 2px solid {border_color};
#                 border-radius: 10px;
#                 padding: 10px 20px;
#                 font-size: 20px;
#                 font-weight: bold;
#             }}
#             QPushButton:pressed {{
#                 background-color: {pressed_color};
#                 border: 2px solid {border_color};
#                 padding: 10px 18px;  /* 点击时按钮稍微变小 */
#             }}
#         """)
#
#     def set_title(self):
#         title = QLabel("系统运行与退出", self)  # 设置标题文字
#         title.setFont(QFont("仿宋", 18))  # 设置字体为仿宋，大小为16
#         title.setAlignment(Qt.AlignCenter)  # 让文字居中
#         title.setGeometry(0, 15, self.width(), 50)  # 设置位置，0为X轴，10为顶部间距，宽度为窗口宽度，高度为30
#         title.setStyleSheet("color: black;  font-weight: bold;")  # 设置字体颜色为黑色
#
#     def stop_detection(self):
#         print("停止检测...")
#         if self.is_detecting:
#             self.is_detecting = False  # 设置为 False，停止检测
#
#
#     def run_code(self):
#         print("运行run代码")
#         # 触发YOLO检测
#         if self.run_detection:
#             self.run_detection()  # 调用主窗口中的run_detection方法
#
#     def exit_system(self):
#         # 退出系统
#         print("正在退出系统...")
#         QApplication.quit()  # 退出应用程序
